<template>
  <el-dialog
    :model-value="dialogVisible"
    :title="dialogTitle"
    width="500px"
    @close="handleClose"
  >
    <el-descriptions class="margin-top" :column="1" :size="large" border>
      <template #extra> </template>
      <el-descriptions-item label="就诊医生">{{
        dialogTableValue.doctor.dname
      }}</el-descriptions-item>
      <el-descriptions-item label="就诊科室">{{
        dialogTableValue.doctor.officename
      }}</el-descriptions-item>
      <el-descriptions-item label="就诊诊室">{{
        dialogTableValue.doctor.room
      }}</el-descriptions-item>
      <el-descriptions-item label="就诊日期">{{
        dialogTableValue.worktime
      }}</el-descriptions-item>
      <el-descriptions-item label="就诊时间">{{
        dialogTableValue.time
      }}</el-descriptions-item>
      <el-descriptions-item label="预约费用">{{
        dialogTableValue.doctor.fee
      }}</el-descriptions-item>
      <el-descriptions-item label="就诊人姓名">{{
        userData1.name
      }}</el-descriptions-item>
      <el-descriptions-item label="电话">{{ userData }}</el-descriptions-item>
      <el-descriptions-item label="身份证">{{
        userData1.idnumber
      }}</el-descriptions-item>
    </el-descriptions>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { defineEmits, defineProps, ref } from 'vue'
import i18n from '@/i18n'
import { ElMessage } from 'element-plus'
import { postYuyue, addRecode } from '@/api/yuyue1-2'
import { useRouter } from 'vue-router'
import { getMyInfo } from '@/api/myinfo'
const router = useRouter()
const props = defineProps({
  dialogTitle: {
    type: String,
    default: '',
    required: true
  },
  dialogTableValue: {
    type: Object,
    default: () => {}
  }
})
console.log(props.dialogTitle)

const userData = JSON.parse(localStorage.getItem('useraccount'))
const userData1 = ref({})
console.log(userData)

const init = async () => {
  const res = await getMyInfo(userData)
  userData1.value = res.data.datas[0]
}
init()
const emits = defineEmits(['update:modelValue', 'initUserList'])

const handleClose = () => {
  emits('update:modelValue', false)
}

const handleConfirm = async () => {
  await handleClick2()
  ElMessage({
    message: i18n.global.t('预约成功'),
    type: 'success'
  })
  emits('initUserList')
  router.push({
    path: 'yuyue'
  })
  handleClose()
}

const handleClick2 = async () => {
  await postYuyue({
    dname: props.dialogTableValue.doctor.dname,
    worktime: props.dialogTableValue.worktime,
    time: props.dialogTableValue.time
  })
  const res = await addRecode({
    dname: props.dialogTableValue.doctor.dname,
    worktime: props.dialogTableValue.worktime,
    time: props.dialogTableValue.time,
    ordertime:
      props.dialogTableValue.worktime + '  ' + props.dialogTableValue.time,
    account: userData + ''
  })
}
</script>

<style></style>